package day06;
import java.util.Arrays;

public class MaxOfArray {
    public static void main(String[] args) {
        /**int[] arr = new int[10];
         for (int i = 0; i < arr.length; i++) {
         arr[i] = (int) (Math.random() * 100 + 1);//填充数据
         System.out.print(arr[i]+"\t");//输出数据
         }
         System.out.println("");//换行


         Arrays.sort(arr);//对arr的升序排列，java中无自带降序方法
         System.out.println("升序后：");
         for (int i = 0; i < arr.length; i++) {
         System.out.print(arr[i]+"\t");
         }
         System.out.println("");//换行

         System.out.println("降序后：");
         for (int i = arr.length-1; i >=0; i--) {
         System.out.print(arr[i]+"\t");
         }*/


        int[] arr1 = {1, 2, 5, 4, 3};
        int max = arr1[0];
        for (int i = 1; i < arr1.length; i++) {
            if (arr1[i] > arr1[0]) {
                max = arr1[i];
            }
        }
        System.out.println("最大值为：" + max);


        arr1 = Arrays.copyOf(arr1, arr1.length + 1);//扩容+1
        arr1[arr1.length - 1] = max;//把最大值赋值给扩容数组的最后一位
        for (int i = 0; i < arr1.length; i++) {//遍历数组
            System.out.println(arr1[i]);
        }

        /** int min = arr1[0];
         for (int j = 1; j < arr1.length; j++) {
         if (arr1[j] < arr1[0]) {
         min = arr1[j];
         }
         }
         System.out.println(min);*/
    }

}